const ws = require('nodejs-websocket')

// 创建一个server
const server = ws.createServer(connect => {
  console.log('有用户连接上来了');
  connect.on('text', data => {
    console.log('接收到了用户的数据',data);
    connect.send(data.toUpperCase() + '!!!')
  })
  connect.on('close', () => {
    console.log('连接断开了');
  })

  connect.on('error', () => {
    console.log('用户连接异常');
  })
})

server.listen(3000, () => {
  console.log('websocket服务启动了,在3000端口');
})